package text111;
import java.util.List;

import java.util.LinkedList;

public class Solution31 {
	//LinkedList<java.util.List<Integer>> res = new LinkedList<java.util.List<Integer>>();
	//返回结果
    LinkedList<List<Integer>> res = new LinkedList<>();
    LinkedList<Integer> path = new LinkedList<>(); 
    public List<List<Integer>> pathSum(TreeNode root, int sum) {
        recur(root, sum);
        return res;
    }
    void recur(TreeNode root, int tar) {
        if(root == null) return;
        path.add(root.val);
        tar -= root.val;
        recur(root.left, tar);
        recur(root.right, tar);   
      	
        if(tar == 0 && root.left == null && root.right == null){
            System.out.println(path);	
            res.add(path);
        }
        //如果不正确删除操作的最后一个值
        path.removeLast();
    }
}
